package com.music.message.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.profile.DefaultProfile;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author 史豪通
 * Date 2024/10/29 10:55
 */
@Configuration
@ConfigurationProperties(prefix = "ali")
@Data
public class MessageConfig {
    private String regionId;
    private String accessKeyId;
    private String secret;
    private String signName;
    private String templateCode;

    @Bean
    public IAcsClient iAcsClient() {
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

    @Bean
    public SendSmsRequest sendSmsRequest() {
        SendSmsRequest request = new SendSmsRequest();
        request.setSignName(signName);
        request.setTemplateCode(templateCode);
        return request;
    }
}
